/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.entity;

import org.ipti.br.tag.entity.enums.WarningType;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;

/**
 *
 * @author luancorumba
 */
@Entity
@SequenceGenerator(name="warningID",sequenceName="warningID", initialValue = 1, allocationSize = 1)
public class Warning implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Long id;
    
//    @ManyToOne
//    private AbstractEntity target;
    
    @ManyToOne
    private Warning father;
    
    @OneToMany(mappedBy="father",fetch= FetchType.LAZY)
    private List<Warning> sons;
    
    private WarningType type;
    
    private boolean resolved = false;

    public Warning() {
    }

    public Warning(AbstractEntity target, WarningType type) {
//        this.target = target;
        this.type = type;
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

//    public AbstractEntity getTarget() {
//        return target;
//    }

//    public void setTarget(AbstractEntity target) {
//        this.target = target;
//    }

    public Warning getFather() {
        return father;
    }

    public void setFather(Warning father) {
        this.father = father;
    }

    public WarningType getType() {
        return type;
    }

    public void setType(WarningType type) {
        this.type = type;
    }

    public List<Warning> getSons() {
        return sons;
    }

    public void setSons(List<Warning> sons) {
        this.sons = sons;
    }

    public boolean isResolved() {
        return resolved;
    }

    public void setResolved(boolean resolved) {
        this.resolved = resolved;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Warning)) {
            return false;
        }
        Warning other = (Warning) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Warning[ id=" + id + " ]";
    }
}
